home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Ken Long / rinth / rinth.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-04  |  14.2 KB  |  608 lines  |  [TEXT/KAHL]

  1. #include <Sound.h>
  2.  
  3. /* The following limits are adequate for displays up to 200x200 */
  4. #define MAX_MAZE_SIZE_X    205
  5. #define MAX_MAZE_SIZE_Y    145
  6. #define LOGOSIZE    20
  7.  
  8. #define MOVE_LIST_SIZE  (MAX_MAZE_SIZE_X * MAX_MAZE_SIZE_Y)
  9.  
  10. #define WALL_TOP            0x8000
  11. #define WALL_RIGHT        0x4000
  12. #define WALL_BOTTOM         0x2000
  13. #define WALL_LEFT             0x1000
  14.  
  15. #define DOOR_IN_TOP        0x0800
  16. #define DOOR_IN_RIGHT    0x0400
  17. #define DOOR_IN_BOTTOM    0x0200
  18. #define DOOR_IN_LEFT        0x0100
  19. #define DOOR_IN_ANY        0x0F00
  20.  
  21. #define DOOR_OUT_TOP        0x0080
  22. #define DOOR_OUT_RIGHT        0x0040
  23. #define DOOR_OUT_BOTTOM    0x0020
  24. #define DOOR_OUT_LEFT        0x0010
  25.  
  26. #define START_SQUARE        0x0002
  27. #define END_SQUARE            0x0001
  28.  
  29. #define SQ_SIZE_X    3
  30. #define SQ_SIZE_Y    3
  31.  
  32. long get_random(long);
  33. long choose_door();
  34. long backup();
  35. long draw_solid_square();
  36. //static long  randnum[NUM_RANDOM];
  37. //Rect pwrect;
  38.  
  39. struct my_mem {
  40.  unsigned long maze[MAX_MAZE_SIZE_X][MAX_MAZE_SIZE_Y];
  41.  struct {
  42.     unsigned char x;
  43.     unsigned char y;
  44.     unsigned char dir;
  45.     } move_list[MOVE_LIST_SIZE],
  46.     save_path[MOVE_LIST_SIZE],
  47.     path[MOVE_LIST_SIZE]; 
  48. };
  49. struct my_mem        *memP;
  50.  
  51. PixPatHandle    pph0, pph1, pph2;
  52.  
  53.  long maze_size_x, maze_size_y, border_x, border_y;
  54.  long sqnum, cur_sq_x, cur_sq_y, path_length;
  55.  long start_x, start_y, start_dir, end_x, end_y, end_dir;
  56. //static long maze_restart_flag, lockcount, colorwindows, random_index;
  57. static long logo_x, logo_y;
  58.  
  59. extern CWindowPtr        gPictureWindow;
  60. extern RGBColor myBlack, myWhite, myGray;
  61. extern Boolean        gDone;
  62. extern Handle        gSolvedSndH;
  63.  
  64. /* main module */
  65. rinth()
  66. {
  67.  
  68.         if ((memP = (struct my_mem *)NewPtr(sizeof(struct my_mem))) == nil)
  69.             return;
  70.             
  71.         if ((pph0 = GetPixPat(128)) == 0)
  72.             return;
  73.         if ((pph1 = GetPixPat(129)) == 0)
  74.             return;
  75.         if ((pph2 = GetPixPat(130)) == 0)
  76.             return;
  77.             
  78.         set_maze_sizes();
  79.  
  80.         initialize_maze();
  81.  
  82.         ErasePort(gPictureWindow, gPictureWindow->portRect);
  83.  
  84.         RGBBackColor(&myBlack);
  85.         RGBForeColor(&myGray);
  86.         draw_maze_border();
  87.  
  88.         create_maze();
  89.  
  90.         if (!gDone)
  91.             solve_maze();
  92.         
  93.         if (!gDone)
  94.             SndPlay(0, gSolvedSndH, 0);
  95.  
  96.         DisposePtr((Ptr)memP);
  97.         DisposePixPat(pph0);
  98.         DisposePixPat(pph1);
  99.         DisposePixPat(pph2);
  100.  
  101. } /*  end of main() */
  102.  
  103.  
  104. set_maze_sizes()
  105. {
  106.     maze_size_x = MAX_MAZE_SIZE_X;
  107.     maze_size_y = MAX_MAZE_SIZE_Y;
  108.  
  109.     border_x = 1;
  110.     border_y = 1;
  111.  
  112. } /* end of set_maze_sizes */
  113.  
  114.  
  115. initialize_maze() /* draw the surrounding wall and start/end squares */
  116. {
  117.     long i, j, wall;
  118.  
  119.     /* initialize all squares */
  120.     for ( i=0; i<maze_size_x; i++) {
  121.         for ( j=0; j<maze_size_y; j++) {
  122.             memP->maze[i][j] = 0;
  123.         }
  124.     }
  125.  
  126.     /* top wall */
  127.     for ( i=0; i<maze_size_x; i++ ) {
  128.         memP->maze[i][0] |= WALL_TOP;
  129.     }
  130.  
  131.     /* right wall */
  132.     for ( j=0; j<maze_size_y; j++ ) {
  133.         memP->maze[maze_size_x-1][j] |= WALL_RIGHT;
  134.     }
  135.  
  136.     /* bottom wall */
  137.     for ( i=0; i<maze_size_x; i++ ) {
  138.         memP->maze[i][maze_size_y-1] |= WALL_BOTTOM;
  139.     }
  140.  
  141.     /* left wall */
  142.     for ( j=0; j<maze_size_y; j++ ) {
  143.         memP->maze[0][j] |= WALL_LEFT;
  144.     }
  145.  
  146.     /* set start square */
  147.     wall = get_random(4);
  148.     switch (wall) {
  149.         case 0:    
  150.             i = get_random(maze_size_x);
  151.             j = 0L;
  152.             break;
  153.         case 1:    
  154.             i = maze_size_x - 1;
  155.             j = get_random(maze_size_y);
  156.             break;
  157.         case 2:    
  158.             i = get_random(maze_size_x);
  159.             j = maze_size_y - 1;
  160.             break;
  161.         case 3:    
  162.             i = 0L;
  163.             j = get_random(maze_size_y);
  164.             break;
  165.     }
  166.     memP->maze[i][j] |= START_SQUARE;
  167.     memP->maze[i][j] |= ( DOOR_IN_TOP >> wall );
  168.     memP->maze[i][j] &= ~( WALL_TOP >> wall );
  169.     cur_sq_x = i;
  170.     cur_sq_y = j;
  171.     start_x = i;
  172.     start_y = j;
  173.     start_dir = wall;
  174.     sqnum = 0;
  175.  
  176.         /* set end square */
  177.         wall = (wall + 2)%4;
  178.         switch (wall) {
  179.                 case 0:
  180.             i = get_random(maze_size_x);
  181.                         j = 0L;
  182.                         break;
  183.                 case 1:
  184.                         i = maze_size_x - 1;
  185.             j = get_random(maze_size_y);
  186.                         break;
  187.                 case 2:
  188.             i = get_random(maze_size_x);
  189.                         j = maze_size_y - 1;
  190.                         break;
  191.                 case 3:
  192.                         i = 0L;
  193.             j = get_random(maze_size_y);
  194.                         break;
  195.         }
  196.         memP->maze[i][j] |= END_SQUARE;
  197.         memP->maze[i][j] |= ( DOOR_OUT_TOP >> wall );
  198.     memP->maze[i][j] &= ~( WALL_TOP >> wall );
  199.     end_x = i;
  200.     end_y = j;
  201.     end_dir = wall;
  202.  
  203.  
  204.     /* set logo */
  205.     if ( (maze_size_x > 15) && (maze_size_y > 15) ) {
  206.         logo_x = get_random(maze_size_x - LOGOSIZE - 6) + 3;
  207.         logo_y = get_random(maze_size_y - LOGOSIZE - 6) + 3;
  208.  
  209.         for (i=0; i<LOGOSIZE; i++) {
  210.             for (j=0; j<LOGOSIZE; j++) {
  211.                 memP->maze[logo_x + i][logo_y + j] |= DOOR_IN_TOP;
  212.             }
  213.         }
  214.     }
  215.     else
  216.         logo_y = logo_x = -1;
  217. }
  218.  
  219.  
  220. create_maze() /* create a maze layout given the intiialized maze */
  221. {
  222.     long i, newdoor;
  223.  
  224.     do {
  225.         memP->move_list[sqnum].x = cur_sq_x;
  226.         memP->move_list[sqnum].y = cur_sq_y;
  227.         memP->move_list[sqnum].dir = newdoor;
  228.         while ( ( newdoor = choose_door() ) == -1 ) { /* pick a door */
  229.             if ( backup() == -1 ) { /* no more doors ... backup */
  230.                 return; /* done ... return */
  231.             }
  232.         }
  233.  
  234.         /* mark the out door */
  235.         memP->maze[cur_sq_x][cur_sq_y] |= ( DOOR_OUT_TOP >> newdoor );
  236.         
  237.         switch (newdoor) {
  238.             case 0: cur_sq_y--;
  239.                 break;
  240.             case 1: cur_sq_x++;
  241.                 break;
  242.             case 2: cur_sq_y++;
  243.                 break;
  244.             case 3: cur_sq_x--;
  245.                 break;
  246.         }
  247.         sqnum++;
  248.  
  249.         /* mark the in door */
  250.         memP->maze[cur_sq_x][cur_sq_y] |= ( DOOR_IN_TOP >> ((newdoor+2)%4) );
  251.  
  252.         /* if end square set path length and save path */
  253.         if ( memP->maze[cur_sq_x][cur_sq_y] & END_SQUARE ) {
  254.             path_length = sqnum;
  255.             for ( i=0; i<path_length; i++) {
  256.                 memP->save_path[i].x = memP->move_list[i].x;
  257.                 memP->save_path[i].y = memP->move_list[i].y;
  258.                 memP->save_path[i].dir = memP->move_list[i].dir;
  259.             }
  260.         }
  261.  
  262.     } while (1);
  263.  
  264. } /* end of create_maze() */
  265.  
  266.  
  267. long
  268. choose_door() /* pick a new path */
  269. {
  270.     long candidates[3];
  271.     long num_candidates;
  272.     long tics;
  273.  
  274.     num_candidates = 0L;
  275.     
  276.     if (gDone)
  277.         return(-1);
  278.  
  279. topwall:
  280.     /* top wall */
  281.     if ( memP->maze[cur_sq_x][cur_sq_y] & DOOR_IN_TOP )
  282.         goto rightwall;
  283.     if ( memP->maze[cur_sq_x][cur_sq_y] & DOOR_OUT_TOP )
  284.         goto rightwall;
  285.     if ( memP->maze[cur_sq_x][cur_sq_y] & WALL_TOP )
  286.         goto rightwall;
  287.     if ( memP->maze[cur_sq_x][cur_sq_y - 1] & DOOR_IN_ANY ) {
  288.         memP->maze[cur_sq_x][cur_sq_y] |= WALL_TOP;
  289.         memP->maze[cur_sq_x][cur_sq_y - 1] |= WALL_BOTTOM;
  290.         draw_wall(cur_sq_x, cur_sq_y, 0L);
  291.         goto rightwall;
  292.     }
  293.     candidates[num_candidates++] = 0;
  294.  
  295. rightwall:
  296.     /* right wall */
  297.     if ( memP->maze[cur_sq_x][cur_sq_y] & DOOR_IN_RIGHT )
  298.         goto bottomwall;
  299.     if ( memP->maze[cur_sq_x][cur_sq_y] & DOOR_OUT_RIGHT )
  300.         goto bottomwall;
  301.     if ( memP->maze[cur_sq_x][cur_sq_y] & WALL_RIGHT )
  302.         goto bottomwall;
  303.     if ( memP->maze[cur_sq_x + 1][cur_sq_y] & DOOR_IN_ANY ) {
  304.         memP->maze[cur_sq_x][cur_sq_y] |= WALL_RIGHT;
  305.         memP->maze[cur_sq_x + 1][cur_sq_y] |= WALL_LEFT;
  306.         draw_wall(cur_sq_x, cur_sq_y, 1L);
  307.         goto bottomwall;
  308.     }
  309.     candidates[num_candidates++] = 1;
  310.  
  311. bottomwall:
  312.     /* bottom wall */
  313. //    Delay(1, &tics);
  314.     if ( memP->maze[cur_sq_x][cur_sq_y] & DOOR_IN_BOTTOM )
  315.         goto leftwall;
  316.     if ( memP->maze[cur_sq_x][cur_sq_y] & DOOR_OUT_BOTTOM )
  317.         goto leftwall;
  318.     if ( memP->maze[cur_sq_x][cur_sq_y] & WALL_BOTTOM )
  319.         goto leftwall;
  320.     if ( memP->maze[cur_sq_x][cur_sq_y + 1] & DOOR_IN_ANY ) {
  321.         memP->maze[cur_sq_x][cur_sq_y] |= WALL_BOTTOM;
  322.         memP->maze[cur_sq_x][cur_sq_y + 1] |= WALL_TOP;
  323.         draw_wall(cur_sq_x, cur_sq_y, 2L);
  324.         goto leftwall;
  325.     }
  326.     candidates[num_candidates++] = 2;
  327.  
  328. leftwall:
  329.     /* left wall */
  330.     if ( memP->maze[cur_sq_x][cur_sq_y] & DOOR_IN_LEFT )
  331.         goto donewall;
  332.     if ( memP->maze[cur_sq_x][cur_sq_y] & DOOR_OUT_LEFT )
  333.         goto donewall;
  334.     if ( memP->maze[cur_sq_x][cur_sq_y] & WALL_LEFT )
  335.         goto donewall;
  336.     if ( memP->maze[cur_sq_x - 1][cur_sq_y] & DOOR_IN_ANY ) {
  337.         memP->maze[cur_sq_x][cur_sq_y] |= WALL_LEFT;
  338.         memP->maze[cur_sq_x - 1][cur_sq_y] |= WALL_RIGHT;
  339.         draw_wall(cur_sq_x, cur_sq_y, 3L);
  340.         goto donewall;
  341.     }
  342.     candidates[num_candidates++] = 3;
  343.  
  344. donewall:
  345.     if (num_candidates == 0)
  346.         return ( -1 );
  347.     if (num_candidates == 1)
  348.         return ( candidates[0] );
  349.     return ( candidates[ get_random(num_candidates) ] );
  350.  
  351. } /* end of choose_door() */
  352.  
  353.  
  354. long
  355. backup() /* back up a move */
  356. {
  357.  
  358. //    HandleEvent();
  359.     if (gDone)
  360.         return(-1);
  361.  
  362.     sqnum--;
  363.     cur_sq_x = memP->move_list[sqnum].x;
  364.     cur_sq_y = memP->move_list[sqnum].y;
  365.     return ( sqnum );
  366. } /* end of backup() */
  367.  
  368.  
  369. draw_maze_border() /* draw the maze outline */
  370. {
  371.     long i, j;
  372.     PicHandle    picH;
  373.     Rect    r;
  374.  
  375.  
  376.     for ( i=0; i<maze_size_x; i++) {
  377.         if ( memP->maze[i][0] & WALL_TOP ) {
  378.         MoveTo(border_x + SQ_SIZE_X * i, border_y);
  379.         LineTo(border_x + SQ_SIZE_X * (i+1), border_y);
  380. //            pw_vector(gfx->gfx_pixwin,
  381. //                border_x + SQ_SIZE_X * i,
  382. //                border_y,
  383. //                border_x + SQ_SIZE_X * (i+1),
  384. //                border_y,
  385. //                PIX_SRC, 1);
  386.         }
  387.         if ((memP->maze[i][maze_size_y - 1] & WALL_BOTTOM)) {
  388.         MoveTo(border_x + SQ_SIZE_X * i, border_y + SQ_SIZE_Y * (maze_size_y));
  389.         LineTo(border_x + SQ_SIZE_X * (i+1), border_y + SQ_SIZE_Y * (maze_size_y));
  390. //            pw_vector(gfx->gfx_pixwin,
  391. //                border_x + SQ_SIZE_X * i,
  392. //                border_y + SQ_SIZE_Y * (maze_size_y),
  393. //                border_x + SQ_SIZE_X * (i+1),
  394. //                border_y + SQ_SIZE_Y * (maze_size_y),
  395. //                PIX_SRC, 1);
  396.         }
  397.     }
  398.     for ( j=0; j<maze_size_y; j++) {
  399.         if ( memP->maze[maze_size_x - 1][j] & WALL_RIGHT ) {
  400.         MoveTo(border_x + SQ_SIZE_X * maze_size_x, border_y + SQ_SIZE_Y * j);
  401.         LineTo(border_x + SQ_SIZE_X * maze_size_x, border_y + SQ_SIZE_Y * (j+1));
  402. //            pw_vector(gfx->gfx_pixwin,
  403. //                border_x + SQ_SIZE_X * maze_size_x,
  404. //                border_y + SQ_SIZE_Y * j,
  405. //                border_x + SQ_SIZE_X * maze_size_x,
  406. //                border_y + SQ_SIZE_Y * (j+1),
  407. //                PIX_SRC, 1);
  408.         }
  409.         if ( memP->maze[0][j] & WALL_LEFT ) {
  410.         MoveTo(border_x, border_y + SQ_SIZE_Y * j);
  411.         LineTo(border_x, border_y + SQ_SIZE_Y * (j+1));
  412. //            pw_vector(gfx->gfx_pixwin,
  413. //                border_x,
  414. //                border_y + SQ_SIZE_Y * j,
  415. //                border_x,
  416. //                border_y + SQ_SIZE_Y * (j+1),
  417. //                PIX_SRC, 1);
  418.         }
  419.     }
  420.  
  421.     picH = GetPicture(128);
  422.     r.top = border_y + SQ_SIZE_Y * logo_y + 2;
  423.     r.left = border_x + SQ_SIZE_X * logo_x + 2;
  424.     r.bottom = r.top + SQ_SIZE_Y * LOGOSIZE - 4;
  425.     r.right = r.left + SQ_SIZE_X * LOGOSIZE - 4;
  426.     DrawPicture(picH, &r);
  427.     ReleaseResource((Handle)picH);
  428.  
  429.     draw_solid_square( start_x, start_y, start_dir, 1L);
  430.     draw_solid_square( end_x, end_y, end_dir, 1L);
  431.  
  432. } /* end of draw_maze() */
  433.  
  434.  
  435. draw_wall(i, j, dir) /* draw a single wall */
  436.     long i, j, dir;
  437. {
  438.     switch (dir) {
  439.         case 0:
  440.         MoveTo(border_x+ SQ_SIZE_X * i, border_y + SQ_SIZE_Y * j);
  441.         LineTo(border_x+ SQ_SIZE_X * (i+1), border_y + SQ_SIZE_Y * j);
  442. //            pw_vector(gfx->gfx_pixwin,
  443. //                border_x + SQ_SIZE_X * i, 
  444. //                border_y + SQ_SIZE_Y * j,
  445. //                border_x + SQ_SIZE_X * (i+1), 
  446. //                border_y + SQ_SIZE_Y * j,
  447. //                PIX_SRC, 1);
  448.             break;
  449.         case 1:
  450.         MoveTo(border_x+ SQ_SIZE_X * (i+1), border_y + SQ_SIZE_Y * j);
  451.         LineTo(border_x+ SQ_SIZE_X * (i+1), border_y + SQ_SIZE_Y * (j+1));
  452. //            pw_vector(gfx->gfx_pixwin,
  453. //                border_x + SQ_SIZE_X * (i+1), 
  454. //                border_y + SQ_SIZE_Y * j,
  455. //                border_x + SQ_SIZE_X * (i+1), 
  456. //                border_y + SQ_SIZE_Y * (j+1),
  457. //                PIX_SRC, 1);
  458.             break;
  459.         case 2:
  460.         MoveTo(border_x+ SQ_SIZE_X * i, border_y + SQ_SIZE_Y * (j+1));
  461.         LineTo(border_x+ SQ_SIZE_X * (i+1), border_y + SQ_SIZE_Y * (j+1));
  462. //            pw_vector(gfx->gfx_pixwin,
  463. //                border_x + SQ_SIZE_X * i, 
  464. //                border_y + SQ_SIZE_Y * (j+1),
  465. //                border_x + SQ_SIZE_X * (i+1), 
  466. //                border_y + SQ_SIZE_Y * (j+1),
  467. //                PIX_SRC, 1);
  468.             break;
  469.         case 3:
  470.         MoveTo(border_x+ SQ_SIZE_X * i, border_y + SQ_SIZE_Y * j);
  471.         LineTo(border_x+ SQ_SIZE_X * i, border_y + SQ_SIZE_Y * (j+1));
  472. //            pw_vector(gfx->gfx_pixwin,
  473. //                border_x + SQ_SIZE_X * i, 
  474. //                border_y + SQ_SIZE_Y * j,
  475. //                border_x + SQ_SIZE_X * i, 
  476. //                border_y + SQ_SIZE_Y * (j+1),
  477. //                PIX_SRC, 1);
  478.             break;
  479.     }
  480. } /* end of draw_wall */
  481.  
  482. long
  483. get_random(modulo)
  484.     long modulo;
  485. {
  486.     return ((unsigned long)Random() % modulo);
  487.  
  488. } /* end of get_random */
  489.  
  490. long
  491. draw_solid_square(i, j, dir, color) /* draw a solid square in a square */
  492.     long i, j, dir, color;
  493. {
  494.     Rect r;
  495.  
  496.     switch (dir) {
  497.         case 0:
  498.             r.left = border_x + 1 + SQ_SIZE_X * i;
  499.             r.top = border_y + SQ_SIZE_Y * j;
  500.             r.right = r.left + SQ_SIZE_X - 1;
  501.             r.bottom = r.top + SQ_SIZE_Y;
  502.             break;
  503.         case 1:
  504.             r.left = border_x + 1 + SQ_SIZE_X * i;
  505.             r.top = border_y + 1 + SQ_SIZE_Y * j;
  506.             r.right = r.left + SQ_SIZE_X;
  507.             r.bottom = r.top + SQ_SIZE_Y - 1;
  508.             break;
  509.         case 2:
  510.             r.left = border_x + 1 + SQ_SIZE_X * i;
  511.             r.top = border_y + 1 + SQ_SIZE_Y * j;
  512.             r.right = r.left + SQ_SIZE_X - 1;
  513.             r.bottom = r.top + SQ_SIZE_Y;
  514.             break;
  515.         case 3:
  516.             r.left = border_x + SQ_SIZE_X * i;
  517.             r.top = border_y + 1 + SQ_SIZE_Y * j;
  518.             r.right = r.left + SQ_SIZE_X;
  519.             r.bottom = r.top + SQ_SIZE_Y - 1;
  520.             break;
  521.     }
  522.     
  523.     switch (color) {
  524.     case 0:
  525.         HLock((Handle)pph1);
  526.         FillCRect(&r, pph1);
  527.         HUnlock((Handle)pph1);
  528.         break;
  529.     case 1:
  530.         HLock((Handle)pph1);
  531.         FillCRect(&r, pph1);
  532.         HUnlock((Handle)pph1);
  533.         break;
  534.     case 2:
  535.         HLock((Handle)pph2);
  536.         FillCRect(&r, pph2);
  537.         HUnlock((Handle)pph2);
  538.         break;
  539.     } /* switch */
  540.  
  541. } /* end of draw_solid_square() */
  542.  
  543. solve_maze() /* solve it with graphical feedback */
  544. {
  545.     int i;
  546.  
  547.     /* plug up the surrounding wall */
  548.     memP->maze[start_x][start_y] |= (WALL_TOP >> start_dir);
  549.     memP->maze[end_x][end_y] |= (WALL_TOP >> end_dir);
  550.  
  551.     /* initialize search path */
  552.     i = 0;
  553.     memP->path[i].x = end_x;
  554.     memP->path[i].y = end_y;
  555.     memP->path[i].dir = -1;
  556.  
  557.     /* do it */
  558.     while (1) {
  559.         if (gDone)
  560.             return;
  561.             
  562.         if ( ++(memP->path[i].dir) >= 4 ) {
  563. //            HandleEvent();
  564.             if (gDone)
  565.                 return;
  566.             i--;
  567.             draw_solid_square( (int)(memP->path[i].x), (int)(memP->path[i].y), 
  568.                 (int)(memP->path[i].dir), 0L);
  569.         }
  570.         else if ( ! (memP->maze[memP->path[i].x][memP->path[i].y] & 
  571.                 (WALL_TOP >> memP->path[i].dir))  && 
  572.                 ( (i == 0) || ( (memP->path[i].dir != 
  573.                 (memP->path[i-1].dir+2)%4) ) ) ) {
  574.             enter_square(i);
  575.             i++;
  576.             if ( memP->maze[memP->path[i].x][memP->path[i].y] & START_SQUARE ) {
  577.                 return;
  578.             }
  579.         } 
  580.     }
  581. } /* end of solve_maze() */
  582.  
  583.  
  584. enter_square(n) /* move into a neighboring square */
  585.     int n;
  586. {
  587.     draw_solid_square( (int)memP->path[n].x, (int)memP->path[n].y, 
  588.         (int)memP->path[n].dir, 2L);
  589.  
  590.     memP->path[n+1].dir = -1;
  591.     switch (memP->path[n].dir) {
  592.         case 0: memP->path[n+1].x = memP->path[n].x;
  593.             memP->path[n+1].y = memP->path[n].y - 1;
  594.             break;
  595.         case 1: memP->path[n+1].x = memP->path[n].x + 1;
  596.             memP->path[n+1].y = memP->path[n].y;
  597.             break;
  598.         case 2: memP->path[n+1].x = memP->path[n].x;
  599.             memP->path[n+1].y = memP->path[n].y + 1;
  600.             break;
  601.         case 3: memP->path[n+1].x = memP->path[n].x - 1;
  602.             memP->path[n+1].y = memP->path[n].y;
  603.             break;
  604.     }
  605.  
  606.  
  607. } /* end of enter_square() */
  608.